package com.example.webdome.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.webdome.mapper.EmailnumberMapper;
import com.example.webdome.pojo.Emailnumber;
import com.example.webdome.service.EmailnumberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

@Service
@Slf4j
public class EmailnumberServiceImpl extends ServiceImpl<EmailnumberMapper, Emailnumber> implements EmailnumberService {


    @Override
    public int getEmailCountByTypeAndDate(LocalDate now) {
        QueryWrapper<Emailnumber> wrapper = new QueryWrapper<>();
        wrapper.eq("time", now);

        try {
            // 执行查询
            Emailnumber emailnumber = this.getOne(wrapper);

            if (emailnumber != null) {
                // 查询成功，返回结果
                return emailnumber.getNumber();
            } else {
                // 查询结果为空
                return 0;
            }
        } catch (Exception e) {
            log.error("查询邮箱信息失败", e);
            return 0;
        }
    }


    @Override
    public void updateCountByEmailTypeAndDate(Emailnumber emailnumber) {
        QueryWrapper<Emailnumber> wrapper = new QueryWrapper<>();
        QueryWrapper<Emailnumber> eq = wrapper.eq("time", emailnumber.getTime());
        if (eq!=null){
            this.update(emailnumber, wrapper);
        }

    }

}
